//
//  HWGiftBagCenterCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2022/9/22.
//  Copyright © 2022 94Wan. All rights reserved.
//

import UIKit

class HWGiftBagCenterCell: UICollectionViewCell {
    var bgView:UIView!
    var logoImageView:UIImageView!
    var nameLabel:UILabel!
    var numLabel:UILabel!
    var model:HWGiftBagCenterModel? {
        didSet {
            logoImageView.kf.setImage(with: URL(string: model?.icon ?? ""))
            nameLabel.text = model?.name
            numLabel.text = "礼包：\(model?.lb_num ?? "")"
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI() -> Void {
        backgroundColor = UIColor.clear
        
        bgView = UIView()
        bgView.layer.cornerRadius = 14*widthScale
        bgView.layer.masksToBounds = true
        bgView.backgroundColor = .white
        contentView.addSubview(bgView)
        
        logoImageView = UIImageView()
        logoImageView.layer.cornerRadius = 10*widthScale
        logoImageView.contentMode = .scaleAspectFill
        bgView.addSubview(logoImageView)
        
        nameLabel = HWLabel.createBoldLabel(title: "", color: "#333333", font: 13*widthScale)
        bgView.addSubview(nameLabel)
        
        numLabel = HWLabel.createLabel(title: "", color: "#888888", font: 11*widthScale)
        bgView.addSubview(numLabel)
    }
    
    func initFrame() -> Void {
        bgView.snp.makeConstraints { make in
//            make.left.equalTo(18*widthScale).priority(.high)
//            make.right.equalTo(-4*widthScale)
//            make.top.equalTo(9*widthScale)
//            make.bottom.equalToSuperview()
            
            make.edges.equalToSuperview()
        }
        
        logoImageView.snp.makeConstraints { make in
            make.left.top.equalTo(9*widthScale)
            make.width.height.equalTo(40*widthScale)
        }
        
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(logoImageView.snp.right).offset(9*widthScale)
            make.top.equalTo(13*widthScale)
            make.height.equalTo(18*widthScale)
            make.right.equalTo(-20*widthScale)
        }
        
        numLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel)
            make.top.equalTo(nameLabel.snp.bottom).offset(3*widthScale)
            make.height.equalTo(15*widthScale)
            make.right.equalTo(nameLabel)
        }
    }
}
